package com.ywb.service.impl;

import com.ywb.mapper.CommodityMapper;
import com.ywb.mapper.EmpMapper;
import com.ywb.mapper.TradeRecordMapper;
import com.ywb.pojo.JobOption;
import com.ywb.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private CommodityMapper commodityMapper;
    @Autowired
    private TradeRecordMapper tradeRecordMapper;
    @Override
    public JobOption getEmpJobData() {
        List<Map<String,Object>> list = empMapper.countEmpJobData();
        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("num")).toList();
        return new JobOption(jobList, dataList);
    }

    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }

    @Override
    public JobOption getContinentTradeData() {
        List<Map<String,Object>> list = commodityMapper.countContinentTradeData();
        List<Object> continentList = list.stream().map(dataMap -> dataMap.get("continent")).toList();
        List<Object> tradeList = list.stream().map(dataMap -> dataMap.get("tradeNum")).toList();
       return new JobOption(continentList, tradeList);
    }

    @Override
    public List<Map<String, Object>> getTypeData() {
        return tradeRecordMapper.countTypeData();
    }

    @Override
    public JobOption getInTradeData() {
        List<Map<String,Object>> list = tradeRecordMapper.countInTradeData();
        List<Object> typeList = list.stream().map(dataMap -> dataMap.get("month")).toList();
        List<Object> tradeList = list.stream().map(dataMap -> dataMap.get("num")).toList();
        return new JobOption(typeList, tradeList);
    }

    @Override
    public JobOption getOutTradeData() {
        List<Map<String,Object>> list = tradeRecordMapper.countOutTradeData();
        List<Object> typeList = list.stream().map(dataMap -> dataMap.get("month")).toList();
        List<Object> tradeList = list.stream().map(dataMap -> dataMap.get("num")).toList();
        return new JobOption(typeList, tradeList);
    }

    @Override
    public JobOption getCommodityData() {
        List<Map<String,Object>> list = commodityMapper.countCommodityData();
        List<Object> commodityList = list.stream().map(dataMap -> dataMap.get("commodity")).toList();
        List<Object> tradeList = list.stream().map(dataMap -> dataMap.get("num")).toList();
        return new JobOption(commodityList, tradeList);
    }

    @Override
    public JobOption getInCTData() {
        List<Map<String,Object>> list = tradeRecordMapper.countInCoutryTradeData();
        List<Object> countryList = list.stream().map(dataMap -> dataMap.get("countryName")).toList();
        List<Object> tradeList = list.stream().map(dataMap -> dataMap.get("num")).toList();
        return new JobOption(countryList, tradeList);
    }

    @Override
    public JobOption getOutCTData() {
        List<Map<String,Object>> list = tradeRecordMapper.countOutCoutryTradeData();
        List<Object> countryList = list.stream().map(dataMap -> dataMap.get("countryName")).toList();
        List<Object> tradeList = list.stream().map(dataMap -> dataMap.get("num")).toList();
        return new JobOption(countryList, tradeList);
    }

    @Override
    public List<Map<String, Object>> getCaNData() {
        return tradeRecordMapper.countCategoryData();
    }
}
